package com.example.mydialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Locale;

public class MyDialog extends Dialog {
    String dialogName;
    Button btnOK,btnCancel;
    EditText myeditText;
    Locale locale = Locale.getDefault();
    public MyDialog(Context context ){
        super(context);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog);
        btnOK = (Button)findViewById(R.id.btnOK);
        btnCancel = (Button)findViewById(R.id.btnCancel);
        myeditText = (EditText)findViewById(R.id.myedit);
        btnOK.setOnClickListener(v-> {
            Editable text = myeditText.getText();
            if(locale.getLanguage().equals("zh")){
                Toast.makeText(getContext(),"你输入的电话号码为："+text.toString(), Toast.LENGTH_LONG).show();
            }else if(locale.getLanguage().equals("en")){
                Toast.makeText(getContext(),"The number you entered is"+text.toString(), Toast.LENGTH_LONG).show();
            }
            dismiss();
        });
        btnCancel.setOnClickListener(v -> {
            dismiss();
        });
    }
}
